package com.wc.算法基础课.D第四讲数学知识.数学期望.扑克牌;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/9 16:09
 * @description https://www.acwing.com/problem/content/220/
 */
public class Main {
    static int A, B, C, D;
    static int N = 14, M = 5;
    static double[][][][][][] f = new double[N][N][N][N][M][M];
    static Scanner sc = new Scanner(System.in);
    static double INF = 1e20;

    /**
     * 翻牌出f[i][j][k][l][m][n] i, j ,k ,l 也就是 a, b, c, d牌被抽出几张，
     * 然后是王牌被抽出了几张的期望, m , n 表示大小王的状态，0 ~ 3表示放到a ~ d堆中
     * 0表示没有被翻出出
     * 分6种情况
     * 抽出红桃  sum表示54 - (a + b + c + d + (x != 4) + (y != 4))， (13 - a) / sum * dp(a + 1, b, c, d, x, y)
     * 抽出黑桃/梅花，方块同理
     * 抽出小王 1 / sum * dp(a, b, c, d, x', y) x' ∈ (1, 2, 3, 4)
     * 大王   1 / sum * dp(a, b, c, d, x, y') y' ∈ (1, 2, 3, 4)
     */
    public static void main(String[] args) {
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        D = sc.nextInt();
        if (isPass(A, B, C, D)) {
            System.out.println("-1.000");
        } else {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    for (int k = 0; k < N; k++) {
                        for (int l = 0; l < N; l++) {
                            for (int m = 0; m < M; m++) {
                                Arrays.fill(f[i][j][k][l][m], -1);
                            }
                        }
                    }
                }
            }
            System.out.printf("%.3f", dp(0, 0, 0, 0, 0, 0));
        }
    }

    static double dp(int a, int b, int c, int d, int x, int y) {
        if (a > 13 || b > 13 || c > 13 || d > 13) return INF;
        if (f[a][b][c][d][x][y] >= 0) return f[a][b][c][d][x][y];
        int as = a + (x == 1 ? 1 : 0) + (y == 1 ? 1 : 0);
        int bs = b + (x == 2 ? 1 : 0) + (y == 2 ? 1 : 0);
        int cs = c + (x == 3 ? 1 : 0) + (y == 3 ? 1 : 0);
        int ds = d + (x == 4 ? 1 : 0) + (y == 4 ? 1 : 0);
        if (as >= A && bs >= B && cs >= C && ds >= D) return f[a][b][c][d][x][y] = 0;
        int sum = 54 - (as + bs + cs + ds);
        if (sum < 0) return f[a][b][c][d][x][y] = INF;
        // 至少翻一张
        double v = 1;
        if (a < 13) v += (13.0 - a) / sum * dp(a + 1, b, c, d, x, y);
        if (b < 13) v += (13.0 - b) / sum * dp(a, b + 1, c, d, x, y);
        if (c < 13) v += (13.0 - c) / sum * dp(a, b, c + 1, d, x, y);
        if (d < 13) v += (13.0 - d) / sum * dp(a, b, c, d + 1, x, y);
        if (x == 0) {
            double t = INF;
            for (int i = 1; i < M; i++) t = Math.min(t, dp(a, b, c, d, i, y));
            v += 1.0 / sum * t;
        }
        if (y == 0) {
            double t = INF;
            for (int i = 1; i < M; i++) t = Math.min(t, dp(a, b, c, d, x, i));
            v += 1.0 / sum * t;
        }
        return f[a][b][c][d][x][y] = v;
    }

    static boolean isPass(int a, int b, int c, int d) {
        return pass13(a) + pass13(b) + pass13(c) + pass13(d) > 2;
    }

    static int pass13(int a) {
        return Math.max(0, a - 13);
    }
}
